﻿using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using NUnit.Framework;
using ScrappyDB.Linq;

namespace ScrappyDB.IntegrationTests.AwsQuery101Examples
{
    [TestFixture]
    public class MultiValuedAttributeTests
    {
        /************************************************************************************
        * Example SQL:          select * from mydomain where Rating = '4 stars' or Rating = '****'  	
        * Description:          Retrieves all items with a 4 star (****) rating.
        *                       The data set has this rating stored as both "4 stars" and "****." Amazon SimpleDB returns items that have either or both. 	
        * Expected result:      1579124585, 0802131786, B000T9886K 
        ************************************************************************************/
        [Test]
        public void OrAnyTest()
        {
            var dbContext = new AwsSampleContext();
            var query = from a in dbContext.Books where a.Rating.Any("4 stars") | a.Rating.Any("****") select a;

            Assert.AreEqual(3, query.ToList().Count);
        }

        /************************************************************************************
        * Example SQL:          select * from mydomain where Keyword = 'Book' and Keyword = 'Hardcover'  	
        * Description:          Retrieve all items that have the Keyword attribute as both "Book" and "Hardcover."
        *                       Based on the data set, you might be surprised that the result did not return the "1579124585" item. 
        *                       As described earlier, each value is evaluated individually against the predicate expression. Since neither of the values satisfies both 
        *                       comparisons defined in the predicate, the item name is not selected.
        *                       To get the desired results, you can use the select * from mydomain where Keyword = 'Book' intersection Keyword = 'Hardcover' expression. 
        *                       For more information, see Multiple Attribute Queries. 	
        * Expected result:      <none>  
        ************************************************************************************/
        [Test]
        public void AndAnyTest()
        {
            var dbContext = new AwsSampleContext();
            var query = from a in dbContext.Books where a.Keywords.Any("Book") & a.Keywords.Any("Hardcover") select a;

            Assert.AreEqual(0, query.ToList().Count);
        }

        /************************************************************************************
        * Example SQL:          select * from mydomain where every(keyword) in ('Book', 'Paperback')  	
        * Description:          Retrieves all items where the only keyword is Book or Paperback. If the item contains any other keyword entries, it is not returned.
        * Expected result:      0385333498, 0802131786  
        ************************************************************************************/
        [Test]
        public void InEveryTest()
        {
            var dbContext = new AwsSampleContext();
            var query = from a in dbContext.Books where a.Keywords.Every("Book", "Paperback") select a;

            Assert.AreEqual(2, query.ToList().Count);
        }
    }
}
